'use strict';

define(['angular', 'angularResource'], function (angular) {
    /* Services */

    // Demonstrate how to register services
    // In this case it is a simple value service.
    angular.module('resource.services', ['ngResource'])
        .value('version', '0.1')
        .factory('$resourceService', function () {
            return {
                queryEnvs : queryEnvs,
                queryHosts : queryHosts
            }
        });

    var queryEnvs = function($http,$scope){
        $http({
            method: "GET",
            url: "api/managers/env"
        }).success(function (data, status) {
            $scope.envs = data.envs;
        }).error(function (data, status) {
            alert("环境查询失败~");
        });
    }

    var queryHosts = function($http,$scope){
        $http({
            method: "GET",
            url: "api/managers/host"
        }).success(function (data, status) {
            $scope.hosts = data.hosts;
        }).error(function (data, status) {
            alert("主机查询失败~");
        });
    }
});
